package nero.yncc.com.createart.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.ArrayList;

import nero.yncc.com.createart.R;
import nero.yncc.com.createart.bean.BeanGoodChangjing;

/**
 * Created by nero on 17-6-27.
 */

public class AdapterGuigeInandIn extends BaseAdapter{

    Context context;
    ArrayList<BeanGoodChangjing.GoodsSpecIn> arrayList;

    public AdapterGuigeInandIn(Context context, ArrayList<BeanGoodChangjing.GoodsSpecIn> arrayList) {
        this.context = context;
        this.arrayList = arrayList;
    }


    @Override
    public int getCount() {
        return arrayList.size();
    }

    @Override
    public Object getItem(int i) {
        return i;
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(final int i, View view, ViewGroup viewGroup) {
        Holder holder;
        if(view==null){
            view= LayoutInflater.from(context).inflate(R.layout.adapter_guige,null,false);
            holder=new Holder(view);
            view.setTag(holder);
        }else{
            holder=(Holder)view.getTag();
        }
        BeanGoodChangjing.GoodsSpecIn bean=arrayList.get(i);
        holder.tv_content.setText(bean.getItem());
        if(bean.isChoose()){
            holder.tv_content.setTextColor(context.getResources().getColor(R.color.project_red_low)) ;
            holder.tv_content.setBackgroundResource(R.drawable.border_red_deep_arc_noround);
        }else{
            holder.tv_content.setTextColor(context.getResources().getColor(R.color.textColorGray)) ;
            holder.tv_content.setBackgroundResource(R.drawable.border_gray_deep_arc_noround);
        }

        holder.tv_content.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                for ( BeanGoodChangjing.GoodsSpecIn bean_cache: arrayList){
                    bean_cache.setChoose(false);
                }
                arrayList.get(i).setChoose(true);
                AdapterGuigeInandIn.this.notifyDataSetChanged();
            }
        });
        return view;
    }

    class Holder{
        TextView tv_content;
        public Holder(View itemView) {
            tv_content=itemView.findViewById(R.id.tv_content);
        }
    }
}
